home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 4 / ETO Development Tools 4.iso / Essentials / MacApp Documentation / MacApp.TECH$ Archives / 1990 / Jun 90 / MacApp.Tech$ 6⁄29⁄90 / 1492-Styled Lengths-Jun90 < prev    next >
Encoding:
Text File  |  1991-03-06  |  5.1 KB  |  169 lines  |  [TEXT/GEOL]

  1. Item forwarded  by  BOSURGI1     to RICHARDSON7
  2.  
  3. Item    3800615                         25-June-90        23:47PDT
  4.  
  5. From:   AUST0334                        AUDev - CRIA, Canberra, ACT,IDV
  6.  
  7. To:     MACAPP.TECH$                    MacApp Technical
  8.  
  9. Sub:    Styled Lengths
  10.  
  11.  
  12. In MacApp 2.0 final, TTEView.CalcRealWidth is only called if the TextEdit is a
  13. non-styled type.
  14.  
  15. It would be better if it was always called, but returned a default width if it
  16. was styled. This would then make it simpler for the rest of us to override the
  17. method to cope with our own peculiar circumstances.
  18.  
  19. Here are the changes I have made to TTEView.CalcRealWidth to facilitate this.
  20. (I have not included here the changes to the calling tests.)
  21. (Note: I have also moved the addition of two insertion point widths into here,
  22. from SynchView)
  23.  
  24.  
  25. {•      CalcRealWidth := aWidth;•}
  26.    {   DBL - Add the space required for I beams here, instead of in SynchView }
  27.     CalcRealWidth := aWidth + kInsertionBarWidth * 2;
  28.    end
  29.   end
  30. {•  else if qDebug then•}
  31. {•   ProgramBreak('IN TTEView.CalcRealWidth: called for a styled TE Record');•}
  32.    {   DBL - I am modifying this routine to return the usual default, instead of
  33. the MacApp technique of }
  34.    {   testing for fStyleType at higher levels }
  35.   else
  36.    CalcRealWidth := fSize.h - fInset.left - fInset.right;
  37.  end;
  38.  
  39.  
  40. In TTEView.CalcRealWidth, there is the following comment:-
  41.  
  42.    { !!! it would be nice to compute this for styled TE but TEGetPoint only
  43. returns the bottom}
  44. {  left of the character box so it can't be used to find the width including
  45. last character}
  46. {  in a line.  And since some characters can change width based on context we
  47. can't just}
  48. {  measure the last character and add it in.  Maybe we can makeup an formula
  49. based on}
  50. {  style runs or something eventually.}
  51.  
  52.  
  53.  
  54. Naturally, our application uses styled TE's, and so here is the formula based
  55. on style runs which we have had to develop.
  56. {==================================================================}
  57. {  TFormTEView.CalcRealWidth }
  58. {==================================================================}
  59.  function TFormTEView.CalcRealWidth: LONGINT;
  60.    { go through all lines of text, and calculate the longest ,  in points}
  61.  
  62. {==================================================================}
  63.   function RunWidth (startChar: INTEGER;
  64.        length: INTEGER;
  65.        hTE: TEHandle): INTEGER;
  66.    var
  67.     aTextStyle: TextStyle;
  68.     lineHeight: INTEGER;
  69.     fontAscent: INTEGER;
  70.     theFontinfo: FontInfo;
  71.   begin
  72.    TEGetStyle(startChar, aTextStyle, lineHeight, fontAscent, hTE);
  73.    SetPortTextStyle(aTextStyle);
  74.    RunWidth := TextWidth(QDPtr(hTE^^.hText^), startChar, length);
  75.   end;
  76.  
  77. {==================================================================}
  78.   function NextStyleAfter (posn: INTEGER;
  79.        hTE: TEHandle): INTEGER;
  80.    var
  81.     theStyleHandle: TEStyleHandle;
  82.     currentRun: INTEGER;
  83.   begin
  84.    NextStyleAfter := hTE^^.teLength + 1;   {   end of text as default }
  85.    theStyleHandle := GetStylHandle(fHTE);
  86.    with theStyleHandle^^ do
  87.    begin
  88.     for currentRun := nRuns - 1 downto 0 do
  89.      if runs[currentRun].startChar > posn then
  90.       NextStyleAfter := runs[currentRun].startChar;
  91.    end;
  92.   end;
  93.  
  94. {==================================================================}
  95.   function LineLength (startChar: INTEGER; { starting character in this line
  96. }
  97.        nextLineStart: INTEGER; { starting character in next line }
  98.        hTE: TEHandle): INTEGER;
  99.    var
  100.     runStart: INTEGER;
  101.     nextRunStart: INTEGER;
  102.     runLength: INTEGER;
  103.     lineTotal: INTEGER;
  104.   begin
  105.    lineTotal := 0;
  106.    runStart := startChar;
  107.    repeat
  108.     nextRunStart := min(nextLineStart, NextStyleAfter(runStart, hTE));
  109.     runLength := nextRunStart - runStart;
  110.     if runLength > 0 then
  111.      lineTotal := lineTotal + RunWidth(runStart, runLength, hTE);
  112.     runStart := nextRunStart;
  113.    until nextRunStart >= nextLineStart;
  114.    LineLength := lineTotal;
  115.   end;
  116.  
  117. {==================================================================}
  118.   const
  119.    kInsertionBarWidth = 1; { We all _KNOW_ an insertion bar is one}
  120.                            {pixel wide right?}
  121.   var
  122.    textWasLocked: BOOLEAN;
  123.    TEWasLocked: BOOLEAN;
  124.    lineWidth: INTEGER;
  125.    currentLine: INTEGER;
  126.    oldPort: GrafPtr;
  127.  begin
  128.   with fHTE^^ do
  129.   begin
  130.    textWasLocked := IsHandleLocked(hText);
  131.    HLock(hText);   {??? Better to LockHandleHigh? }
  132.    TEWasLocked := IsHandleLocked(fHTE);
  133.    HLock(HANDLE(fHTE));{??? Better to LockHandleHigh? }
  134.  
  135.    lineWidth := 0;
  136.    maxCharWidth := 0;  { will be updated during linewidth calcs }
  137.    if teLength > 0 then
  138.    begin
  139.     GetPort(oldPort);
  140.     SetPort(gWorkPort);
  141.  
  142.     Assert(nLines > 0, 'TFormTEView . CalcRealWidth - nLines = 0');
  143.     for currentLine := 0 to nLines - 1 do
  144.      lineWidth := MAX(lineWidth, LineLength(lineStarts[currentLine],
  145. lineStarts[currentLine + 1], fHTE));
  146.  
  147.     lineWidth := lineWidth + kInsertionBarWidth * 2;
  148.  
  149.  
  150.     SetPort(oldPort);
  151.     if not textWasLocked then
  152.      HUnlock(hText);
  153.     if not TEWasLocked then
  154.      HUnlock(HANDLE(fHTE));
  155.    end;
  156.   end;
  157.  end;
  158.  
  159.  
  160. There. Wasn't so bad after all, was it?
  161.  
  162. Don Lawn
  163. Techway Solutions
  164. Canberra, Australia
  165. AppleLink:  AUST0334
  166.  
  167.  
  168.  
  169.